home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / dev / misc / FlexCat.lha / Lib / C_c.sd < prev    next >
Text File  |  1999-11-28  |  5KB  |  233 lines

  1. ##rem $Id: C_c.sd,v 1.2 1999/11/28 03:36:41 carlos Exp $
  2. ##stringtype C
  3. ##shortstrings
  4. /****************************************************************
  5.    This file was created automatically by `%fv'
  6.    from "%f0".
  7.  
  8.    Do NOT edit by hand!
  9. ****************************************************************/
  10.  
  11. /****************************************************************
  12.     This file uses the auto initialization possibilities of
  13.     Dice, gcc and SAS/C, respectively.
  14.  
  15.     Dice does this by using the keywords __autoinit and
  16.     __autoexit, SAS uses names beginning with _STI or
  17.     _STD, respectively. gcc uses the asm() instruction,
  18.     to emulate C++ constructors and destructors.
  19.  
  20.     Using this file you don't have *all* possibilities of
  21.     the locale.library. (No Locale or Language arguments are
  22.     supported when opening the catalog. However, these are
  23.     *very* rarely used, so this should be sufficient for most
  24.     applications.
  25. ****************************************************************/
  26.  
  27.  
  28. /*
  29.     Include files and compiler specific stuff
  30. */
  31. #include <exec/memory.h>
  32. #include <libraries/locale.h>
  33. #include <libraries/iffparse.h>
  34.  
  35. #include <proto/exec.h>
  36. #include <proto/dos.h>
  37. #include <proto/locale.h>
  38. #include <proto/utility.h>
  39. #include <proto/iffparse.h>
  40.  
  41. #include <stdlib.h>
  42. #include <string.h>
  43.  
  44.  
  45.  
  46. #include "%b_cat.h"
  47.  
  48.  
  49. /*
  50.     Variables
  51. */
  52. struct FC_String %b_Strings[%n] = {
  53.     { (STRPTR) %s, %d }%(,)
  54. };
  55.  
  56. STATIC struct Catalog *%bCatalog = NULL;
  57. #ifdef LOCALIZE_V20
  58. STATIC STRPTR %bStrings = NULL;
  59. STATIC ULONG %bStringsSize;
  60. #endif
  61.  
  62.  
  63. #if defined(_DCC)
  64. STATIC __autoexit VOID _STDClose%bCatalog(VOID)
  65. #elif defined(__SASC)
  66. VOID _STDClose%bCatalog(VOID)
  67. #elif defined(__GNUC__)
  68. STATIC VOID _STDClose%bCatalog(VOID)
  69. #else
  70. VOID Close%bCatalog(VOID)
  71. #endif
  72.  
  73. {
  74.     if (%bCatalog) {
  75.     CloseCatalog(%bCatalog);
  76.     }
  77. #ifdef LOCALIZE_V20
  78.     if (%bStrings) {
  79.     FreeMem(%bStrings, %bStringsSize);
  80.     }
  81. #endif
  82. }
  83.  
  84.  
  85. #if defined(_DCC)
  86. STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
  87. #elif defined(__SASC)
  88. VOID _STIOpen%bCatalog(VOID)
  89. #elif defined(__GNUC__)
  90. VOID _STIOpen%bCatalog(VOID)
  91. #else
  92. VOID Open%bCatalog(VOID)
  93. #endif
  94.  
  95. {
  96.     if (LocaleBase) {
  97.     if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
  98.                      OC_BuiltInLanguage, %l,
  99.                      OC_Version, %v,
  100.                      TAG_DONE))) {
  101.         struct FC_String *fc;
  102.         int i;
  103.  
  104.         for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
  105.          fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
  106.         }
  107.     }
  108.     }
  109. }
  110.  
  111. #if defined(__GNUC__)
  112. __asm ("  .text;  .stabs \\\"___CTOR_LIST__\\\",22,0,0,__STIOpen%bCatalog");
  113. __asm ("  .text;  .stabs \\\"___DTOR_LIST__\\\",22,0,0,__STDClose%bCatalog");
  114. #endif
  115.  
  116.  
  117.  
  118. #ifdef LOCALIZE_V20
  119. VOID Init%bCatalog(STRPTR language)
  120.  
  121. {
  122.     struct IFFHandle *iffHandle;
  123.  
  124.     /*
  125.     **  Use iffparse.library only, if we need to.
  126.     */
  127.     if (LocaleBase  ||  !IFFParseBase  ||  !language  ||
  128.     Stricmp(language, %l) == 0) {
  129.     return;
  130.     }
  131.  
  132.     if ((iffHandle = AllocIFF())) {
  133.     char path[128]; /* Enough to hold 4 path items (dos.library 3.1)    */
  134.     strcpy(path, "PROGDIR:Catalogs");
  135.     AddPart((STRPTR) path, language, sizeof(path));
  136.     AddPart((STRPTR) path, "%b.catalog", sizeof(path));
  137.     if (!(iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))) {
  138.         strcpy(path, "LOCALE:Catalogs");
  139.         AddPart((STRPTR) path, language, sizeof(path));
  140.         AddPart((STRPTR) path, language, sizeof(path));
  141.         iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  142.     }
  143.  
  144.     if (iffHandle->iff_Stream) {
  145.         InitIFFasDOS(iffHandle);
  146.         if (!OpenIFF(iffHandle, IFFF_READ)) {
  147.         if (!PropChunk(iffHandle, MAKE_ID('C','T','L','G'),
  148.                    MAKE_ID('S','T','R','S'))) {
  149.             struct StoredProperty *sp;
  150.             int error;
  151.  
  152.             for (;;) {
  153.             if ((error = ParseIFF(iffHandle, IFFPARSE_STEP))
  154.                    ==  IFFERR_EOC) {
  155.                 continue;
  156.             }
  157.             if (error) {
  158.                 break;
  159.             }
  160.  
  161.             if ((sp = FindProp(iffHandle, MAKE_ID('C','T','L','G'),
  162.                        MAKE_ID('S','T','R','S')))) {
  163.                 /*
  164.                 **  Check catalog and calculate the needed
  165.                 **  number of bytes.
  166.                 **  A catalog string consists of
  167.                 **      ID (LONG)
  168.                 **      Size (LONG)
  169.                 **      Bytes (long word padded)
  170.                 */
  171.                 LONG bytesRemaining;
  172.                 LONG *ptr;
  173.  
  174.                 %bStringsSize = 0;
  175.                 bytesRemaining = sp->sp_Size;
  176.                 ptr = (LONG *) sp->sp_Data;
  177.  
  178.                 while (bytesRemaining > 0) {
  179.                 LONG skipSize, stringSize;
  180.  
  181.                 ptr++;                  /*  Skip ID     */
  182.                 stringSize = *ptr++;
  183.                 skipSize = ((stringSize+3) >> 2);
  184.  
  185.                 %bStringsSize += stringSize+1;  /*  NUL */
  186.                 bytesRemaining -= 8 + (skipSize << 2);
  187.                 ptr += skipSize;
  188.                 }
  189.  
  190.                 if (!bytesRemaining  &&
  191.                 (%bStrings = AllocMem(%bStringsSize, MEMF_ANY))) {
  192.                 STRPTR sptr;
  193.  
  194.                 bytesRemaining = sp->sp_Size;
  195.                 ptr = (LONG *) sp->sp_Data;
  196.                 sptr = %bStrings;
  197.  
  198.                 while (bytesRemaining) {
  199.                     LONG skipSize, stringSize, id;
  200.                     struct FC_String *fc;
  201.                     int i;
  202.  
  203.                     id = *ptr++;
  204.                     stringSize = *ptr++;
  205.                     skipSize = ((stringSize+3) >> 2);
  206.  
  207.                     CopyMem(ptr, sptr, stringSize);
  208.                     bytesRemaining -= 8 + (skipSize << 2);
  209.                     ptr += skipSize;
  210.  
  211.                     for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
  212.                     if (fc->id == id) {
  213.                         fc->msg = sptr;
  214.                     }
  215.                     }
  216.  
  217.                     sptr += stringSize;
  218.                     *sptr++ = '\\0';
  219.                 }
  220.                 }
  221.                 break;
  222.             }
  223.             }
  224.         }
  225.         CloseIFF(iffHandle);
  226.         }
  227.         Close(iffHandle->iff_Stream);
  228.     }
  229.     FreeIFF(iffHandle);
  230.     }
  231. }
  232. #endif
  233.